<!DOCTYPE html>
<html>
<body>
<canvas id="physics-canvas" width="500" height="360"></canvas>
<script>
const canvas = document.getElementById('physics-canvas');
const ctx = canvas.getContext('2d');

// Style settings
ctx.lineWidth = 2;
ctx.strokeStyle = 'black';
ctx.fillStyle = 'black';

// --- Helper function for B-field symbol ---
function drawBField(x, y) {
    const radius = 12;
    ctx.save();
    ctx.lineWidth = 1.5;
    // Circle
    ctx.beginPath();
    ctx.arc(x, y, radius, 0, 2 * Math.PI);
    ctx.stroke();
    // Cross
    ctx.beginPath();
    ctx.moveTo(x - radius * 0.707, y - radius * 0.707);
    ctx.lineTo(x + radius * 0.707, y + radius * 0.707);
    ctx.moveTo(x + radius * 0.707, y - radius * 0.707);
    ctx.lineTo(x - radius * 0.707, y + radius * 0.707);
    ctx.stroke();
    // Label B
    ctx.font = 'italic bold 22px Times New Roman';
    ctx.fillText('B', x + radius + 5, y + 8);
    ctx.restore();
}

// --- Main Drawing ---

// Parameters
const centerX = 250;
const centerY = 170;
const radius = 75;
const groundY = centerY + radius;

// Ground plane
ctx.beginPath();
ctx.moveTo(30, groundY);
ctx.lineTo(470, groundY);
ctx.stroke();

// Ground hatching
ctx.save();
ctx.lineWidth = 1;
for (let i = 40; i < 470; i += 15) {
    ctx.beginPath();
    ctx.moveTo(i, groundY);
    ctx.lineTo(i - 10, groundY + 10);
    ctx.stroke();
}
ctx.restore();

// Ring
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
ctx.stroke();

// Ring labels: m, Q
ctx.font = 'italic 20px Times New Roman';
ctx.fillText('m,Q', centerX - 20, centerY - radius - 15);

// Ring center O
ctx.font = '20px Times New Roman';
ctx.fillText('O', centerX + 5, centerY + 7);

// Dashed radius R
ctx.save();
ctx.setLineDash([5, 5]);
ctx.beginPath();
ctx.moveTo(centerX, centerY);
const angle = (5/4) * Math.PI; // -135 degrees
ctx.lineTo(centerX + radius * Math.cos(angle), centerY + radius * Math.sin(angle));
ctx.stroke();
ctx.restore();

// Label R
ctx.font = 'italic 20px Times New Roman';
ctx.fillText('R', centerX - 35, centerY + 35);

// Magnetic Field B
drawBField(100, 70);
drawBField(400, 70);

// Velocity vector v0
const arrowY = centerY;
const arrowStartX = centerX + radius + 10;
const arrowEndX = arrowStartX + 70;
ctx.beginPath();
ctx.moveTo(arrowStartX, arrowY);
ctx.lineTo(arrowEndX, arrowY);
ctx.stroke();
// Arrowhead
ctx.beginPath();
ctx.moveTo(arrowEndX, arrowY);
ctx.lineTo(arrowEndX - 10, arrowY - 5);
ctx.moveTo(arrowEndX, arrowY);
ctx.lineTo(arrowEndX - 10, arrowY + 5);
ctx.stroke();

// Velocity label v0
ctx.font = 'italic bold 20px Times New Roman';
ctx.fillText('v', arrowEndX + 10, arrowY + 2);
ctx.font = '14px Times New Roman';
ctx.fillText('0', arrowEndX + 21, arrowY + 6);

// Friction coefficient μ
ctx.font = 'italic 20px Times New Roman';
ctx.fillText('μ', 280, groundY + 25);

// Directional labels
ctx.font = '24px Simsun';
ctx.fillText('西', 60, groundY - 10);
ctx.fillText('东', 390, groundY - 10);

// Figure caption
ctx.font = '20px Simsun';
ctx.fillText('电图 2.9.1', 200, groundY + 60);

</script>
</body>
</html>